home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #045 (1990)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #045 (1990)(Amiga User Group Deutschland e.V.).adf / AtoI&ItoA / AtoI.c < prev    next >
C/C++ Source or Header  |  1989-07-02  |  4KB  |  149 lines

  1. /* AtoI - wandelt AMIGA-Textfiles in IBM-Textfiles um.
  2.    Das Problem: Der IBM benutzt andere ASCII-Codes als der AMIGA. Dies macht
  3.    sich vor allem bei den deutschen Umlauten und dem ß bemerkbar.
  4.    Dieses Programm macht ein AMIGA-Textfile für die Übertragung zum IBM bereit.
  5.    Syntax:
  6.    AtoI <AMIGAfile> <IBMfile>
  7.    <AMIGAfile> : Name des zu konvertierenden Files
  8.    <IBMfile>   : Name des Ausgabefiles, das anschließend per AREAD vom IBM-
  9.          Emulator gelesen werden kann.
  10.  
  11.    23.3.1989 Tim Pietzcker Software
  12.    Dieses Programm basiert auf dem Programm ItoA, das dieselbe Aufgabe in
  13.    umgekehrter Richtung verrichtet. Im Wesentlichen mußten nur die Tabelle
  14.    umgedreht und ein paar Texte geändert werden. So ergänzen sich die beiden
  15.    Programme optimal.
  16.  
  17.    Kopieren, Ergänzen, Verstümmeln etc. erwünscht.
  18. */
  19.  
  20. #include <exec/types.h>
  21. #include <exec/memory.h>
  22. #include <libraries/dos.h>
  23.  
  24. #define CONVTBLENGTH 14        /* wenn die Tabelle erweitert wird, einfach
  25.                    neue Anzahl hier eintragen */
  26. #define BUFSIZE      4096l
  27.  
  28. struct Library    *OpenLibrary();
  29. struct DosBase    *DosBase;
  30. struct FileHandle *source,*dest,*Open();
  31. UBYTE          *buffer,*sourcename,*destname,*AllocMem();
  32. UBYTE          ConvTable[] =
  33.           /* links AMIGA,rechts IBM */
  34.             { 196,142,    /* Ä */
  35.               214,153,    /* Ö */
  36.               220,154,    /* Ü */
  37.               228,132,    /* ä */
  38.               246,148,    /* ö */
  39.               252,129,    /* ü */
  40.               223,225 };    /* ß */
  41. LONG          len;
  42.  
  43. open_files(src,dst)
  44. UBYTE *src,*dst;
  45. {
  46.    source=Open(src,MODE_OLDFILE);
  47.    if (source==NULL) 
  48.    {
  49.       printf("Unable to open source file : %s\n",src);
  50.       get_out();
  51.    }
  52.    dest=Open(dst,MODE_NEWFILE);
  53.    if (dest==NULL)
  54.    {
  55.       printf("Unable to open destination file : %s\n",dst);
  56.       get_out();
  57.    }
  58. }
  59.  
  60. get_out()
  61. {
  62.    if (DosBase) CloseLibrary(DosBase);
  63.    if (source)  Close(source);
  64.    if (dest)    Close(dest);
  65.    if (buffer)  FreeMem(buffer,BUFSIZE);
  66.    exit(TRUE);
  67. }
  68.  
  69. convert_block(buf,length) /* wandelt einen Block von BUFSIZE Bytes oder weniger
  70.                  ins richtige Format um */
  71. UBYTE *buf;
  72. LONG length;
  73. {
  74.    UBYTE *ptr;
  75.    LONG i;
  76.    int j;
  77.    for(ptr=buf,i=0;i<length;++i,++ptr)
  78.       if(*ptr & 0x80) /* ASCII-Code > 128 ? */
  79.          for(j=0;j < CONVTBLENGTH; j+=2)    /* Tabelle absuchen */
  80.         if(*ptr == ConvTable[j]) *ptr=ConvTable[j+1];
  81.  
  82.    i=Write(dest,buf,length);
  83.    if (i<0)
  84.    {
  85.       printf("Error writing destination file !\n");
  86.       get_out();
  87.    }
  88. }
  89.  
  90. convert_texts()
  91. {
  92.    long done=FALSE;
  93.    while(done==FALSE)    /* solange, bis EOF erreicht */
  94.    {
  95.       len=Read(source,buffer,BUFSIZE);
  96.       if (len<=0)    /* Error oder fertig ? */
  97.       {
  98.          if (len<0)
  99.          {
  100.             printf("Error reading source file !\n");
  101.         get_out();
  102.          }
  103.          done=TRUE;
  104.       }   
  105.       else
  106.          convert_block(buffer,len);
  107.    }
  108. }
  109.  
  110. open_dos()
  111. {
  112.    DosBase=(struct DosBase *)OpenLibrary("dos.library",0l);
  113.    if (DosBase==NULL) exit(FALSE);
  114.    buffer=AllocMem(BUFSIZE,MEMF_CLEAR); 
  115.    if (buffer==NULL)
  116.    {
  117.       printf("Out of Memory !\n");
  118.       get_out();
  119.    }
  120. }
  121.  
  122. usage(filename)        /* erklärt die korrekte Syntax bei Fehlaufruf */
  123. UBYTE *filename;
  124. {
  125.    printf("USAGE : %s <AMIGAfile> <IBMfile>\n",filename);
  126.    printf("\n<AMIGAfile> : Name (AMIGA-DOS) of the file to be converted\n");
  127.    printf("<IBMfile>   : Name of the destination file name (AMIGA-DOS).\n");
  128.    printf("              This file can then be read by the IBM Emulator.\n");
  129.    exit(FALSE);
  130. }
  131.  
  132. main(argc,argv)
  133. int argc;
  134. UBYTE *argv[];
  135. {
  136.    /* Testen, ob Aufruf korrekt */
  137.    if (argc<2 || argc>3 || argc==2 && *argv[1]=='?') usage(argv[0]);
  138.    open_dos();
  139.    sourcename = argv[1];
  140.    destname   = argv[2];
  141.    
  142.    open_files(sourcename,destname);
  143.    
  144.    convert_texts();
  145.    get_out();
  146. }
  147.  
  148. /* End of Source */
  149.